﻿using System;
using System.Collections.Generic;

using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using AMG.DALProfile;
using System.Web.UI.HtmlControls;

namespace AMG.Web
{
    public partial class edit : AMG.Web.UI.Page.UserPage
    {
        public string amgcode = "";
        public string username = "";
        public string sex = "";
        public string city = "";
        public string customerproperty = "";
        public string company = "";
        public string position = "";
        public string crno = "";
        public string driverlisecen = "";
        public string phone = "";
        public string address = "";
        public string mail = "";
        public string zipcode = "";
        public string isbook = "";
        public string carno = "";
        public string arrivaldate = "";
        public string arrivaltraffic = "";
        public string trafficno = "";
        public string starth = "";
        public string startm = "";
        public string endh = "";
        public string endm = "";
        public string startcity = "";
        public string needget = "";
        public string returndate = "";
        public string returntraffic = "";
        public string trafficno1 = "";
        public string returnh = "";
        public string returnm = "";
        public string returncity = "";
        public string needsend = "";
        public string room = "";
        public string golf = "";
        public string equipment = "";
        public string golftime = "";
        public string R = "";
        public int roundno;

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {

                R = Request.QueryString["r"];
                AMG.DALSQLServer.AMG_UserInfo us = new AMG.DALSQLServer.AMG_UserInfo();
                AMG.Model.AMG_UserInfo usinfo = us.GetModel(int.Parse(Request.QueryString["r"]));
                amgcode = usinfo.AMGCode;
                username = usinfo.UserName;
                sex1.Checked = true;
                if (usinfo.Sex == false)
                {
                    sex1.Checked = true;
                }
                else
                {
                    sex2.Checked = true;
                }
                company = usinfo.Company;
                if (UserID == 29)
                {
                    BindDropDownList(ddlRound, "SELECT   AMG_Round_Company.RoundID, AMG_Round.RoundName, AMG_Round.BookNo FROM AMG_Round_Company INNER JOIN  AMG_Round ON AMG_Round_Company.RoundID = AMG_Round.ID INNER JOIN AMG_Proxy ON AMG_Round_Company.CompanyID = AMG_Proxy.ID where AMG_Proxy.ID=" + usinfo.CompanyID);
                }
                else
                {
                    BindDropDownList(ddlRound, "SELECT   AMG_Round_Company.RoundID, AMG_Round.RoundName, AMG_Round.BookNo FROM AMG_Round_Company INNER JOIN  AMG_Round ON AMG_Round_Company.RoundID = AMG_Round.ID INNER JOIN AMG_Proxy ON AMG_Round_Company.CompanyID = AMG_Proxy.ID where AMG_Proxy.ID=" + UserID);
                }
                position = usinfo.Positison;
                crno = usinfo.CRNo;
                if (usinfo.DriverLisecen == false)
                {
                    driverlisecen2.Checked = true;
                }
                else
                {
                    driverlisecen1.Checked = true;
                }
                phone = usinfo.Phone;
                address = usinfo.Address;
                mail = usinfo.Mail;
                zipcode = usinfo.ZipCode;
                if (usinfo.IsBook == true)
                {
                    isbook1.Checked = true;
                    DataTable dt = DbHelper.ExecuteTable(CommandType.Text, "select CarID from AMG_Book where UserID='"+ R +"'", null);
                    for (int i = 0; i <= dt.Rows.Count - 1; i++)
                    {
                        if (dt.Rows[i][0].ToString() == "1")
                        {
                            C63.Checked = true;
                        }
                        if (dt.Rows[i][0].ToString() == "2")
                        {
                            SLK55.Checked = true;
                        }
                        if (dt.Rows[i][0].ToString() == "3")
                        {
                            SL63.Checked = true;
                        }
                        if (dt.Rows[i][0].ToString() == "4")
                        {
                            S65.Checked = true;
                        }
                        if (dt.Rows[i][0].ToString() == "5")
                        {
                            CLS63.Checked = true;
                        }
                        if (dt.Rows[i][0].ToString() == "6")
                        {
                            G55.Checked = true;
                        }
                        if (dt.Rows[i][0].ToString() == "7")
                        {
                            ML63.Checked = true;
                        }
                    }

                }
                else
                {
                    isbook2.Checked = true;
                }
                carno = usinfo.CarNo.ToString();
                if (usinfo.CarNo > 0)
                {
                    cars.InnerHtml=addtr(usinfo.CarNo);
                }
                ddlRound.SelectedValue = usinfo.RoundNo.ToString ();
                checktable(Request.QueryString["r"]);
                DataBind();
            }
        }

        private void checktable(string id)
        {
            unsubmit.InnerHtml = "<table width=\"563\" border=\"0\" align=\"center\" cellpadding=\"0\" cellspacing=\"0\" class=\"infotab\"> ";
            AMG.DALSQLServer.AMG_UserInfo us = new AMG.DALSQLServer.AMG_UserInfo();
            AMG.Model.AMG_UserInfo usinfo = us.GetModel(int.Parse(id));
            if (usinfo.UserName == null || usinfo.UserName == "")
            {
                unsubmit.InnerHtml += "<tr><td class=\"redcolor\"><p>客户姓名</p></td><td class=\"redcolor\">&nbsp;</td></tr>";
            }
            
            if (usinfo.Company == null || usinfo.Company == "")
            {
                unsubmit.InnerHtml += "<tr><td class=\"redcolor\"><p>公司名称</p></td><td class=\"redcolor\">&nbsp;</td></tr>";
            }
            if (usinfo.Positison == null || usinfo.Positison == "")
            {
                unsubmit.InnerHtml += "<tr><td class=\"redcolor\"><p>职位</p></td><td class=\"redcolor\">&nbsp;</td></tr>";
            }
            if (usinfo.CRNo == null || usinfo.CRNo == "")
            {
                unsubmit.InnerHtml += "<tr><td class=\"redcolor\"><p>身份证号</p></td><td class=\"redcolor\">&nbsp;</td></tr>";
            }
            if (usinfo.Phone == null || usinfo.Phone == "")
            {
                unsubmit.InnerHtml += "<tr><td class=\"redcolor\"><p>电话号码</p></td><td class=\"redcolor\">&nbsp;</td></tr>";
            }
            if (usinfo.Address == null || usinfo.Address == "")
            {
                unsubmit.InnerHtml += "<tr><td class=\"redcolor\"><p>邮寄地址</p></td><td class=\"redcolor\">&nbsp;</td></tr>";
            }
            if (usinfo.ZipCode == null || usinfo.ZipCode == "")
            {
                unsubmit.InnerHtml += "<tr><td class=\"redcolor\"><p>邮政编码</p></td><td class=\"redcolor\">&nbsp;</td></tr>";
            }
            if (usinfo.Mail == null || usinfo.Mail == "")
            {
                unsubmit.InnerHtml += "<tr><td class=\"redcolor\"><p>电子信箱</p></td><td class=\"redcolor\">&nbsp;</td></tr>";
            }
            
            unsubmit.InnerHtml += "<tr><td >&nbsp;</td></tr><tr><td >&nbsp;</td></tr></table>";
        }

        public string checknull(string str)
        {
            if (str == null || str == "")
            {
                return "*未填写";
            }
            else
            {
                return str;
            }
        }

        public void getSelect(HtmlSelect select, string str, bool bl)
        {
            for (int i = 0; i < select.Items.Count; i++)
            {
                if (bl)
                {
                    if (str == select.Items[i].Text)
                    {
                        select.Value = select.Items[i].Value;
                        break;
                    }
                }
                else
                {
                    if (str == select.Items[i].Value)
                    {
                        select.Value = select.Items[i].Value;
                        break;
                    }
                }
            }
        }

        private string addtr(int num)
        {
            string innerhtml = "";
            if (num != 0 && num != 99)
            {
                DataTable dt = DbHelper.ExecuteTable(CommandType.Text, "select CarName,CarBland from AMG_Cars where UserID='" + R + "'", null);
                innerhtml = "<table width=\"560\" border=\"0\" align=\"center\" cellpadding=\"0\" cellspacing=\"15\" class=\"infotab\" >";
                for (int i = 0; i <= num - 1; i++)
                {
                    innerhtml += "<tr><td width=\"105\" class=\"center\"><div align=\"right\">品牌和车型</div></td><td width=\"284\" class=\"center\" style=\"padding-left:30px; \"><input name=\"carbland" + (i + 1).ToString() + "\" type=\"text\" class=\"tbwidth02\" size=\"15\" width=\"80\" value=\"" + dt.Rows[i][0].ToString() + "\"/><input name=\"carname" + (i + 1).ToString() + "\" type=\"text\" class=\"tbwidth02\" size=\"15\" width=\"80\" value=\"" + dt.Rows[i][1].ToString() + "\"/></td><td width=\"111\" class=\"center\">&nbsp;</td></tr>";
                }
                innerhtml += "</table>";
            }
            return innerhtml;

        }

        public static void BindDropDownList(System.Web.UI.WebControls.DropDownList ddl, string sql)
        {
            if (sql == null || sql == "")
            {
                ddl.Items.Clear();
                return;
            }

            DataTable dt = DbHelper.ExecuteTable(CommandType.Text, sql, null);
            ddl.DataSource = dt;
            ddl.DataTextField = dt.Columns[1].ColumnName;
            ddl.DataValueField = dt.Columns[0].ColumnName;
            ddl.SelectedIndex = 0;
            ddl.SelectedValue = null;
            ddl.DataBind();
        }
    }
}
